﻿@model  List<FTBS.Models.Entities.Concert.ShowTimeConcertEntity>
@{
    var searchSchedule = (FTBS.Models.Entities.Concert.SearchSchedule)ViewBag.SearchSchedule;
    var date = Model[0].DateOfSchedule;
    var deadlineForBooking = (int)ViewBag.DeadLineForBooking;
}
<div>
    @if (Model.Count > 0)
    {
        var listDay = new List<DateTime>();

        foreach (var day in Model)
        {
            if (!listDay.Contains(day.DateOfSchedule))
            {
                listDay.Add(day.DateOfSchedule);
            }
        }

        foreach (var day in listDay)
        {
        <div style="overflow: auto; width: 270px">
            <div style="float: left">
                @day.ToString("dd/MM/yyyy")
            </div>
            <hr style="margin-top: 20px; background-color: black;" />
            @foreach (var item in Model)
            {
                if (item.DateOfSchedule == day)
                {
                <div style="float: left; padding-left: 5px; margin-top: -20px; margin-bottom: 10px;">
                    @{
                    string minutes = "";
                    string hours = "";
                    if (item.Time.Minutes < 10)
                    {
                        minutes = "0" + item.Time.Minutes.ToString();
                    }
                    else if (item.Time.Minutes >= 10)
                    {
                        minutes = item.Time.Minutes.ToString();
                    }

                    if (item.Time.Hours < 10)
                    {
                        hours = "0" + item.Time.Hours.ToString();
                    }
                    else if (item.Time.Hours >= 10)
                    {
                        hours = item.Time.Hours.ToString();
                    }

                    var currentYear = DateTime.Now.Year;
                    var currentMonth = DateTime.Now.Month;
                    var currentDay = DateTime.Now.Day;
                    var currentHour = DateTime.Now.Hour;

                    var showtimeYear = item.DateOfSchedule.Year;
                    var showtimeMonth = item.DateOfSchedule.Month;
                    var showtimeDay = item.DateOfSchedule.Day;
                    var showtimeHour = item.Time.Hours;

                    if (showtimeYear < currentYear)
                    {
                        <button class="button small" style="background-color: brown; text-emphasis-color: black; margin-top: 5px" disabled>
                            <div style="color: black; float: left">@hours:@minutes</div>
                        </button>
                    }
                    else
                    {
                        if (showtimeYear > currentYear)
                        {
                            <button class="button small info" style="float: left; margin-top: 15px">
                                @Html.ActionLink(hours + ":" + minutes, "BookingAFilmTicket", new { @showtimeId = item.ShowTimeId, @filmId = searchSchedule.FilmId, @theaterId = searchSchedule.TheaterId, @roomId = item.RoomId, @scheduleId = item.ScheduleId })
                            </button>
                        }
                        else
                        {
                            if (showtimeMonth >= currentMonth)
                            {
                                if (showtimeMonth == currentMonth)
                                {

                                    if (showtimeDay > currentDay)
                                    {
                                            <button class="button small info" style="float: left; margin-top: 15px">
                                                @Html.ActionLink(hours + ":" + minutes, "BookingAFilmTicket", new { @showtimeId = item.ShowTimeId, @filmId = searchSchedule.FilmId, @theaterId = searchSchedule.TheaterId, @roomId = item.RoomId, @scheduleId = item.ScheduleId })
                                            </button>
                                    }
                                    else if (showtimeDay == currentDay)
                                    {
                                        if (showtimeHour >= currentHour + (deadlineForBooking / 60))
                                        {
                                            <button class="button small info" style="float: left">
                                                @Html.ActionLink(hours + ":" + minutes, "BookingAFilmTicket", new { @showtimeId = item.ShowTimeId, @filmId = searchSchedule.FilmId, @theaterId = searchSchedule.TheaterId, @roomId = item.RoomId, @scheduleId = item.ScheduleId })
                                            </button>
                                        }
                                        else
                                        {
                                            <button class="button small" style="background-color: brown; text-emphasis-color: black; margin-top: 15px" disabled>
                                                <div style="color: black; float: left">@hours:@minutes</div>
                                            </button>
                                        }
                                    }
                                    else
                                    {
                                        <button class="button small" style="background-color: brown; text-emphasis-color: black; margin-top: 15px" disabled>
                                            <div style="color: black; float: left">@hours:@minutes</div>
                                        </button>
                                    }
                                }
                                else
                                {
                                    <button class="button small info" style="float: left; margin-top: 15px">
                                        @Html.ActionLink(hours + ":" + minutes, "BookingAFilmTicket",
                                                                                                            new
                                                                                                            {
                                                                                                                @showtimeId = item.ShowTimeId,
                                                                                                                @filmId = searchSchedule.FilmId,
                                                                                                                @theaterId = searchSchedule.TheaterId,
                                                                                                                @roomId = item.RoomId,
                                                                                                                @scheduleId = item.ScheduleId
                                                                                                            })
                                    </button>
                                }
                            }
                            else
                            {
                                <button class="button small" style="background-color: brown; text-emphasis-color: black; margin-top: 15px" disabled>
                                    <div style="color: black; float: left">@hours:@minutes</div>
                                </button>
                            }
                        }
                    }
                    }
                </div>
                }
            }
        </div>
        }
    }
</div>
